import { createRouter, createWebHistory } from 'vue-router'
import Aside from '../components/aside.vue'
import Login from '../login/login.vue'
import Admin from '../views/admin.vue'
import { useStore } from "vuex";
// const val = useStore().state.login_mess
const routes = [
  {path:'/',redirect:'login'},
  {
    path: '/aside',
    name: 'aside',
    component: Aside,
    
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
   
  },
  {
    path: '/admin',
    name: 'admin',
    component: Admin,
    beforeEnter: (to, from, next) => {
      // console.log(useStore().state.login_mess.user);
      if (useStore().state.login_mess.user !=  undefined) {
        next();
      } else {
        // 在跳转到login页面的时候携带一个isLogin:false参数
        next({ path: '/login', query: { isLogin: false } }, { isLogin: false })

        // next({path:'/login?isLogin:false'})
      }
    },
    children:[
      {path:'/admin/class',component:()=>import('../views/class.vue')},
      {path:'/admin/users',component:()=>import('../views/users.vue')},
      {path:'/admin/notes',component:()=>import('../views/notes.vue')},
      {path:'/admin/articles',component:()=>import('../views/articles.vue')},
      {path:'/admin/doctors',component:()=>import('../views/doctors.vue')},
      {path:'/admin/sign',component:()=>import('../views/sign.vue')},
    ]
  }
]
const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
